using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data.OleDb;

namespace DAOLayer
{
    public class ThamSoDao
    {
        public static void CapNhatXuongCSDL(ThamSoDto ts)
        {
            OleDbConnection cn = Database.ConnectionData();
            //'B3: Tao chuoi strSQL thao tac CSDL
            String strSQL = "Update THAMSO Set SoKhachToiDa = ? ,TyLePhuThu = ? ,SoLuongLoaiKhach = ?  , SoLuongLoaiPhong = ?  ";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@SoKhachToiDa", OleDbType.Integer);
            cmd.Parameters["@SoKhachToiDa"].Value = ts.SoLuongKhachToiDa;
            cmd.Parameters.Add("@TyLePhuThu", OleDbType.Double);
            cmd.Parameters["@TyLePhuThu"].Value = ts.TyLePhuThu;
            cmd.Parameters.Add("@SoLuongLoaiKhach", OleDbType.Integer);
            cmd.Parameters["@SoLuongLoaiKhach"].Value = ts.SoLuongLoaiKhach;
            cmd.Parameters.Add("@SoLuongLoaiPhong", OleDbType.Integer);
            cmd.Parameters["@SoLuongLoaiPhong"].Value = ts.SoLuongLoaiPhong;
            cmd.ExecuteNonQuery();
            cn.Close();
        }
        public static ThamSoDto LayThamSo()
        {
            ThamSoDto ts = new ThamSoDto();
            // B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
            OleDbConnection cn = Database.ConnectionData();
            //'B3: Tao chuoi strSQL thao tac CSDL
            String strSQL = "Select * From THAMSO ";
            //'B4: Thuc thi chuoi strSQL
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                ts.SoLuongKhachToiDa = (int)dr["SoKhachToiDa"];
                ts.TyLePhuThu = (double)dr["TyLePhuThu"];
                ts.SoLuongLoaiPhong = (int)dr["SoLuongLoaiPhong"];
                ts.SoLuongLoaiKhach = (int)dr["SoLuongLoaiKhach"];
            }
            cn.Close();
            return ts;
        }
       
    }
}
